/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package util;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import obj.Person;
import org.jibble.simpleftp.SimpleFTP;

/**
 *
 * @author jm1156
 */
public class FileFTPUtil {
    
    private static SimpleFTP ftp = null;
    
    
    private static SimpleFTP getConnection() {
        try {
            if(ftp == null) {
                ftp = new SimpleFTP();
                
                // Connect to an FTP server on port 21.
                ftp.connect("66.197.136.195", 21, "ftp_user", "ftp_user");
            }
            return ftp;
        } catch (IOException ex) {
            ex.printStackTrace();
            return null;
        }
    }
    
    public static boolean uploadFile(Person patient, Person user, String filename) {
        return uploadFile(patient, user, new File(filename));
    }
    
    public static boolean uploadFile(Person patient, Person user, File file) {
        try {
            SimpleFTP ftp = getConnection();

            // Upload some files.
            ftp.stor(file);
            
            // Quit from the FTP server.
            ftp.disconnect();
            
            ftp = null;
        } catch(IOException io_ex) {
            return false;
        }
        return true;
    }
    
    public static boolean downloadFile(Person patient, Person user, String filename) {
        return true;
    }
    
    public static boolean downloadFile(Person patient, Person user, File file) {
        return true;
    }
    
    public static ArrayList<File> getListOfFiles(Person patient, Person user) {
        ArrayList<File> listOfFiles = new ArrayList<File>();
        return listOfFiles;
    }
    
    public static void main(String[] args){
        FileFTPUtil.getConnection();
        FileFTPUtil.uploadFile(null, null, "C:/Users/David/Pictures/android_nom.jpg");
        //FileFTPUtil.downloadFile(null, null, "C:/Users/David/Pictures/android_nom.jpg");
        
    }
}
